(function () {
    const response = {
        data: {
            type: "page",
            body: [
                {
                    type: "hbox",
                    columns: [
                        {
                            type: "form",
                            title: "",
                            submitText: "",
                            mode: "horizontal",
                            body: [
                                {
                                    label: "模板组",
                                    type: "list-select",
                                    name: "groupCode",
                                    clearable: true,
                                    selectFirst: true,
                                    source: "/api/templateGroup/listSelect"
                                },
                                {
                                    label: "模板编号",
                                    type: "list-select",
                                    name: "code",
                                    clearable: true,
                                    source: "/api/template/listSelect?groupCode=${groupCode}",
                                    initFetchOn: "data.groupCode",
                                    selectFirst: true,
                                },
                            ],
                            onEvent: {
                                change: {
                                    actions: [
                                        {
                                            actionType: "setValue",
                                            componentId: "mainForm",
                                            args: {
                                                value: "$$"
                                            }
                                        }
                                    ]
                                }
                            }
                        },
                        {
                            type: "form",
                            title: "",
                            submitText: "",
                            mode: "horizontal",
                            body: [
                                {
                                    label: "数据库",
                                    type: "list-select",
                                    name: "dataSourceCode",
                                    clearable: true,
                                    selectFirst: true,
                                    source: "/api/dataSource/listSelect"
                                },
                                {
                                    label: "表",
                                    type: "list-select",
                                    name: "tableName",
                                    clearable: true,
                                    selectFirst: true,
                                    source: "/api/tableinfo/listSelect?dataSourceCode=${dataSourceCode}",
                                    initFetchOn: "data.dataSourceCode",
                                },
                            ],
                            onEvent: {
                                change: {
                                    actions: [
                                        {
                                            actionType: "setValue",
                                            componentId: "mainForm",
                                            args: {
                                                value: "$$"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    ]
                },
                {
                    type: "hbox",
                    columns: [
                        {
                            type: "form",
                            id: "mainForm",
                            name: "mainForm",
                            initApi: {
                                method: "get",
                                url: "/api/template/findByGroupCodeAndCode?groupCode=${groupCode}&code=${code}",
                                sendOn: "${!ISEMPTY(groupCode) && !ISEMPTY(code)}"
                            },
                            api: "post:/api/template/edit/${id}",
                            title: "",
                            body: [
                                {
                                    label: "",
                                    type: "plaintext-editor",
                                    name: "content",
                                    size: "xxl"
                                }
                            ],
                            actions: [
                                {
                                    type: "button",
                                    label: "预览",
                                    actionType: "dialog",
                                    level: "warning",
                                    dialog: {
                                        title: "",
                                        size: "lg",
                                        actions: [],
                                        body: {
                                            type: "form",
                                            initApi: {
                                                method: "post",
                                                url: "/api/template/previewByContent",
                                                data: {
                                                    id: "${id}",
                                                    content: "${content}",
                                                    dataSourceCode: "${dataSourceCode}",
                                                    tableName: "${tableName}"
                                                }
                                            },
                                            body: [
                                                {
                                                    type: "xml-editor",
                                                    size: "xxl",
                                                    name: "createFileContent",
                                                }
                                            ]
                                        }
                                    }
                                },
                                {
                                    type: "button",
                                    actionType: "submit",
                                    label: "保存",
                                    level: "primary",
                                    messages: {
                                        success: "模板保存成功",
                                        failed: "模板保存失败",
                                    }                                    
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        status: 0
    }

    window.jsonpCallback && window.jsonpCallback(response);
})();
